package com.ruoyi.activiti;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

import java.io.File;
import java.io.FileOutputStream;

public class X6ToBpmn {
    public static void createXml() {
        try {
            // 创建document对象
            Document document = DocumentHelper.createDocument();
            // 创建根节点rss
            Element rss = document.addElement("rss");
            // 向rss节点添加属性
            rss.addAttribute("version", "2.0");
            // 向rss节点添加子节点
            Element channel = rss.addElement("channel");
            Element title = channel.addElement("title");
            title.setText("国内最新新闻");
            // 设置生成xml的格式
            OutputFormat format = OutputFormat.createPrettyPrint();
            format.setEncoding("UTF-8");
            // 生成xml文件
            File file = new File("rss.xml");
            System.out.println("file = " + file.getAbsolutePath());
            XMLWriter writer = new XMLWriter(new FileOutputStream(file), format);
            // 设置是否转义，默认使用转义字符
            writer.setEscapeText(false);
            writer.write(document);
            writer.close();
            System.out.println("生成xml文件成功");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("生成xml文件失败");
        }
    }

    public static void main(String[] args) {
        createXml();
    }
}
